/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package baitap;

import java.util.Scanner;

/**
 *
 * @author Nhim
 */
public class Bai8 {
    public static void main(String[] args) {
        for(long i = 1000000; i <= 9999999; i++){
            if(Csngto(i)) if(Csotang(i)) if(Nguyento(i)) System.out.println(i);
        }
    }
    public static boolean Nguyento(long n){
        if(n < 2) return false;
        for(int i = 2; i <= Math.sqrt(n); i++) if(n % i == 0 ) return false;
        return true;
    }
    public static boolean Csngto(long n){
        while(n > 0){
            long i =  n % 10;
            if(i == 0 || i == 1|| i == 4|| i == 6|| i == 8|| i == 9){
                return false;
            }
            n = n / 10;
        }
        return true;
    }
    public static boolean Csotang(long n){
        while(n > 10){
            long i = n % 10;
            long j = (n / 10) % 10;
            if(i < j) return false;
            n = n / 10;
        }
        return true;
    }
}
